#ifndef GPS_H_
#define GPS_H_


#ifdef __cplusplus
extern "C"
{
#endif

//Definition of GPS Register
#define GPS_ADDR 				0x42
#define GPS_BYTE_NUMBER_MSB 	0xFD
#define GPS_BYTE_NUMBER_LSB 	0xFE
#define GPS_DATA_STREAM			0xFF

#define GPS_MAX_DATA_SIZE 255


typedef struct gps_data_t{
	Uint8 data[GPS_MAX_DATA_SIZE];
	size_t length;
}GPS_param;

typedef struct GGA{
	float	UTCTime;
	float 	Latitude;
	float	Longitude;
	Uint8	FS;
	Uint8	SatNum;
	float	HDOP;
	float	MSL;
	float	Altref;
	float	DiffAge;
	Uint8	DiffStation;
	Uint16	Checksum;
} GGA;

typedef struct NAVSOL{
	Uint32	iTOW;		//GPS Millisecond Time of Week, Unit ms
	Int32 	fTOW;	 	//Fractional Nanoseconds remainder of rounded ms above, range -500000 .. 500000, Unit ns
	Int16	WEEK;		//GPS week
	float	TimeLable;	//Use (iTOW*1000 + fTOW / 1000 = us) or (7*24*3600*WEEK*1000000 + iTOW*1000 + fTOW / 1000 = us) as time lable
	Uint8	gpsFix;		//GPS Fix Type, range 0..5
	Uint8	flags;		//Fix Status Flags
	Int32	ecefX;		//ECEF X
	Int32	ecefY;		//ECEF Y
	Int32	ecefZ;		//ECEF Z
	Uint32	pAcc;		//3D Position Accuracy Estimate
	Int32	ecefVX;		//ECEF X
	Int32	ecefVY;		//ECEF Y
	Int32	ecefVZ;		//ECEF Z
	Uint32	sAcc;		//Speed Accuracy Estimate
	Uint16	pDOP;		//Position DOP
	Uint8	numSV;		//Number of SVs used in Nav Solution
	Uint16	Checksum;	//Checksum A & B, A in High Byte, B in Low Byte
} NAVSOL;

typedef struct RXMRAW_GEN{
	Uint32 iTOW;		//GPS Millisecond Time of Week, Unit ms
	Int16  WEEK;		//GPS week
	Uint8  numSV;		//Number of SVs
	//Uint16 COM_ID;	//Command ID
} RXMRAW_GEN;

typedef struct RXMRAW_SAT{
	double	cpMes;		//Carrier phase measurement (L1 cycles)
	double	prMes;		//Pseudorange measurement (m)
	float	doMes;		//Doppler measurement (Hz)
	Uint8	svID;		//Space vehicle number
	Int8	mesQI;		//Nav measurements quality >=4:PR+DO ok; >=5:PR+DO+CP ok; <6: likely loss of carrier lock
	Int8	cno;		//Signal strength dbHz
	Uint8	lli;		//loss of lock indicator (RINEX definition)

} RXMRAW_SAT;		//Maximum 9 SVs can be observed in the air at the same time


int GPS_i2cRead(GIO_Handle inhd,GIO_Handle outhd, Uint8 REG, Uint8 *buf, size_t len);
int GPS_i2cWrite(GIO_Handle outhd, Uint8 * txbuf, size_t msglen);
int GPS_process_data(NAVSOL *p, Uint8 *data);	//save received data to a NAVSOL struct and return a point to this NAVSOL struct
int GPS_process_rawdata(RXMRAW_GEN *raw_gen,RXMRAW_SAT *raw_sat[], Uint8 *data);


#ifdef __cplusplus
}
#endif /* extern "C" */


#endif /*GPS_H_*/
